<?php


namespace App\Admin\Actions\Import;

use App\Extensions\Action;
use App\Services\Import\PatentGradeImportService;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class PatentEstimateImportTool extends Action
{
    protected $selector = '.patent-estimate-import-post';

    public function handle(Request $request)
    {
        $rows = Excel::toCollection(collect([]), $request->file('file'))->first();
        $server = new PatentGradeImportService();
        foreach ($rows as $key => $row) {
            if ($key) {
                $server->importScore($row);
            }
        }
        return $this->response()->success('导入成功')->refresh();
    }

    public function form()
    {
        $this->file('file', '请选择文件');
    }

    public function html()
    {
        return $this->htmlButton('导入分级分类');
    }

}
